<template>
  <div class="oe-add-question" v-loading="loading">
    <top-tip v-if="courseTitle" :courseTitle="courseTitle"></top-tip>
    <div class="oe-add-question__content">
      <a-tabs defaultActiveKey="1" v-model="defaultActiveKey">
        <a-tab-pane tab="题库" key="1">
          <div style="display: table-cell;width: 200px;">
            <div style="height: 944px;overflow: auto;backgroundColor: #ffffff">
              <tree-select @change="getQuestionBankList" ref="tree" :list="treeList"></tree-select>
              <div style="text-align: center; font-size: 16px; color: #0177d5; cursor: pointer;text-decoration: underline;">
                <span v-if="treeList.length == 0" @click="function(){defaultActiveKey = '2'}">[ 前往编辑知识点 ]</span>
              </div>
            </div>
          </div>
          <div style="display: table-cell;width: calc(100% - 200px);">
            <div class="oe-question-search">
              <span class="oe-question-select"> 
                <a-select
                  v-model="selectType1"
                  @change="typechange"
                  showSearch
                  :allowClear="true"
                  optionFilterProp="children"
                  placeholder="全部题型"
                  style="width: 160px"
                >
                  <a-select-option v-for="(item, index) in typelist" :value="item.id" :index="index" :key="item.id">
                    {{ item.text }}
                  </a-select-option>
                </a-select>
              </span>
              <span class="oe-question-select">
                <a-select
                  v-model="selectType2"
                  @change="diffchange"
                  showSearch
                  :allowClear="true"
                  optionFilterProp="children"
                  placeholder="全部难度"
                  style="width: 120px"
                >
                  <a-select-option v-for="(item, index) in defficulty" :value="item.id" :index="index" :key="item.id">{{
                    item.text
                  }}</a-select-option>
                </a-select>
              </span>
              <span class="oe-question-text">题干：</span>
              <span class="oe-question-input">
                <a-input placeholder="输入题干名称" v-model="quiz" />
              </span>

              <span class="oe-question-text">状态：</span>
              <span class="oe-question-select">
                <a-select
                  v-model="selectType3"
                  @change="disableStateChange"
                  :allowClear="true"
                  optionFilterProp="children"
                  placeholder="全部"
                  style="width: 120px"
                >
                  <a-select-option
                    v-for="(item, index) in disablestate"
                    :value="item.id"
                    :index="index"
                    :key="item.id"
                    >{{ item.text }}</a-select-option
                  >
                </a-select>
              </span>

              <span class="oe-question-btns">
                <a-button type="primary" @click.stop="getQuestionBankList">查询</a-button>
              </span>
            </div>
            <div class="oe-question-fns">
              <a-button v-if="operationList.includes('add/edit/del:ques')" @click="modify">修改知识点</a-button>
              <a-button v-if="operationList.includes('add/edit/del:ques')" @click="deleteQuestion">批量删除</a-button>
              <a-button v-if="operationList.includes('add/edit/del:ques')" @click="clickAction('新增题目')"
                >新增题目</a-button
              >
              <a-button v-if="isShow && operationList.includes('add/edit/del:ques')" @click="importQues"
                >职教云导入</a-button
              >
              <a-button v-if="isShow && operationList.includes('add/edit/del:ques')" @click="importZykQues"
                >资源库导入</a-button
              >
              <a-button v-if="operationList.includes('add/edit/del:ques')" @click="importExcelQues">Excel导入</a-button>
              <a-button v-if="operationList.includes('add/edit/del:ques')" @click="importworddQues">Word导入</a-button>
              <a-button>
                <a :href="exportUrl">导出题目</a>
              </a-button>
              <a-button v-if="checkDuplicateData == '0'" @click="checkDuplicateClick()">题目查重</a-button>
              <a-button v-if="checkDuplicateData == '1'" @click="checkDuplicateClick()">取消查重</a-button>
              <a-button @click="disableQuestionClick()">批量禁用</a-button>
              <a-button @click="relieveDisableQuestionClick()">批量解禁</a-button>
            </div>
            <div class="oe-question-container">
              <a-table
                v-if="questionlistShow"
                :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectquestion }"
                :columns="columns"
                :dataSource="dataList"
                :pagination="pagination"
                @change="onTableChange"
              >
                <span slot="titleText" slot-scope="text, record">
                  <div class="oe-question-titleText">
                    <span v-html="record.title"></span>
                  </div>
                </span>
                <span slot="action" slot-scope="text, record">
                  <a-tooltip placement="bottom" title="查看">
                    <span
                      @click="clickAction('查看', record)"
                      v-if="operationList.includes('add/edit/del:ques')"
                      class="action-icon"
                    >
                      <i class="iconfont icon-chakan"></i>
                      <span>查看</span>
                    </span>
                  </a-tooltip>
                  <a-tooltip placement="bottom" title="编辑" class="bianji">
                    <span
                      @click="clickAction('题库编辑', record)"
                      v-if="operationList.includes('add/edit/del:ques')"
                      class="action-icon"
                    >
                      <i class="iconfont icon-edit"></i>
                      <span>编辑</span>
                    </span>
                  </a-tooltip>
                  <a-tooltip placement="bottom" title="删除">
                    <span
                      @click="clickAction('题库删除', record)"
                      v-if="operationList.includes('add/edit/del:ques')"
                      class="action-icon"
                    >
                      <i class="iconfont icon-delete"></i>
                      <span>删除</span>
                    </span>
                  </a-tooltip>
                </span>
                <span v-if="!operationList.includes('add/edit/del:ques')">--</span>
              </a-table>
            </div>
          </div>
          <!-- 知识点修改 -->
          <a-modal title="知识点修改" class="oe-exam-modal" centered v-model="visible">
            <span class="oe-question-select" style="height: 344px;overflow: auto;display: block;" v-if="visible">
              <tree-select ref="treemodal" :width="'100%'" :linkage="linkage" :list="treeList"></tree-select>
            </span>
            <div slot="footer">
              <a-button type="primary" @click="sureModify">确认</a-button>
              <a-button @click.stop="visible = false">取消</a-button>
            </div>
          </a-modal>
          <!-- 从职教云导入 -->
          <a-modal title="从职教云导入" class="oe-questionzjy" :visible="imported" width="70%" @cancel="importedCancel">
            <div class="oe-select-table" style="display: table-cell;width: calc(100% - 200px);">
              <div class="oe-select" style="margin-left: 10px;">
                <span class="oe-manage-select">
                  <a-select
                    v-model="questionType"
                    @change="typechange"
                    showSearch
                    :allowClear="true"
                    optionFilterProp="children"
                    placeholder="选择全部题型"
                    style="width: 140px"
                  >
                    <a-select-option v-for="(item, index) in typelist" :value="item.id" :index="index" :key="item.id">
                      {{ item.text }}
                    </a-select-option>
                  </a-select>
                </span>
                <span class="oe-manage-select">
                  <a-select
                    v-model="defficultyLevel"
                    @change="diffchange"
                    showSearch
                    :allowClear="true"
                    optionFilterProp="children"
                    placeholder="全部难度"
                    style="width: 140px"
                  >
                    <a-select-option v-for="(item, index) in defficulty" :value="item.id" :index="index" :key="item.id">
                      {{ item.text }}
                    </a-select-option>
                  </a-select>
                </span>
                <span class="oe-select-input">
                  <a-input placeholder="请输入题干" v-model="titleText_select" />
                </span>
                <span class="oe-select-input">
                  <a-input placeholder="请输入课程名称" v-model="CourseName" />
                </span>
                <span class="oe-select-input">
                  <a-input placeholder="请输入知识点" v-model="knowledgeTitle" />
                </span>
                <a-button type="primary" @click.stop="getZjyDataList">查询</a-button>
              </div>
              <a-table
                :rowSelection="{ selectedRowKeys: selectedRowKeysZjy, onChange: onSelectDataZjy }"
                :columns="importedColumns"
                :dataSource="importedDatas"
                :scroll="{ y: 400 }"
                :pagination="paginationZjy"
                @change="onZjyTableChange"
              >
                <span slot="action" slot-scope="text, record">
                  <a-tooltip placement="bottom" title="查看">
                    <span @click="clickActionIcve(record)" class="action-icon">
                      <i style="cursor: pointer" class="iconfont icon-chakan"></i>
                    </span>
                  </a-tooltip>
                </span>
              </a-table>
            </div>
            <div style="display: table-cell;width: 200px;border-left: 1px solid #ccc;">
              <div style="height: 35px; background: #1890ff; text-align: center; font-size: 18px; color: #fff; line-height: 35px;">
                关联知识点
                <a-tooltip placement="bottom">
                  <template slot="title">
                    <span>选择要导入题目的知识点</span>
                  </template>
                  <a-icon type="question-circle" style="color: #f00;cursor: pointer;" />
                </a-tooltip>
              </div>
              <div style="max-height: 500px;overflow: auto;">
                <tree-select ref="treeQuestionzjy" :linkage="linkage" :list="treeList" v-if="imported"></tree-select>
              </div>
            </div>
            <template slot="footer">
              <a-button @click="importedSure" type="primary" html-type="submit">确定</a-button>
              <a-button @click.stop="importedCancel">取消</a-button>
            </template>
          </a-modal>
          <!-- 从资源库导入 -->
          <a-modal
            title="从资源库导入"
            class="oe-questionzyk"
            :visible="importedZyk"
            width="75%"
            @cancel="importedCancelZyk"
          >
            <div class="oe-select-table" style="display: table-cell;width: calc(100% - 200px);">
              <div class="oe-select oe-questionzjy" style="margin-bottom: 20px">
                <span class="oe-manage-select">
                  <a-select
                    v-model="projectId"
                    @change="projectchange"
                    showSearch
                    :allowClear="false"
                    optionFilterProp="children"
                    style="width: 140px"
                  >
                    <a-select-option
                      v-for="(item, index) in projectList"
                      :value="item.Id"
                      :index="index"
                      :key="item.Id"
                      >{{ item.Name }}</a-select-option
                    >
                  </a-select>
                </span>
                <span class="oe-manage-select">
                  <a-select
                    v-model="knowledgeaOne"
                    @change="knowledgeaOnechange"
                    showSearch
                    :allowClear="true"
                    optionFilterProp="children"
                    style="width: 140px"
                    placeholder="全部"
                  >
                    <a-select-option
                      v-for="(item, index) in knowledgeaOneList"
                      :value="item.Id"
                      :index="index"
                      :key="item.Id"
                    >
                      {{ item.Name }}
                    </a-select-option>
                  </a-select>
                </span>

                <span class="oe-manage-select" v-if="knowledgeaOne">
                  <a-select
                    v-model="knowledgeaTwo"
                    @change="knowledgeaTwochange"
                    showSearch
                    :allowClear="true"
                    optionFilterProp="children"
                    style="width: 140px"
                    placeholder="全部"
                  >
                    <a-select-option
                      v-for="(item, index) in knowledgeaTwoList"
                      :value="item.Id"
                      :index="index"
                      :key="item.Id"
                    >
                      {{ item.Name }}
                    </a-select-option>
                  </a-select>
                </span>
                <span class="oe-manage-select">
                  <a-select
                    v-model="questionType"
                    @change="typechange"
                    showSearch
                    :allowClear="true"
                    optionFilterProp="children"
                    placeholder="选择全部题型"
                    style="width: 140px"
                  >
                    <a-select-option v-for="(item, index) in typelistZYK" :value="item.id" :index="index" :key="item.id">
                      {{ item.text }}
                    </a-select-option>
                  </a-select>
                </span>
                <span class="oe-manage-select">
                  <a-select
                    v-model="defficultyLevel"
                    @change="diffchange"
                    showSearch
                    :allowClear="true"
                    optionFilterProp="children"
                    placeholder="全部难度"
                    style="width: 140px"
                  >
                    <a-select-option v-for="(item, index) in difficulty" :value="item.id" :index="index" :key="item.id">
                      {{ item.text }}
                    </a-select-option>
                  </a-select>
                </span>
                <span class="oe-manage-select oe-select-input">
                  <a-input placeholder="请输入题干" v-model="questionName" />
                </span>
                <a-button type="primary" @click.stop="getZykDataList">查询</a-button>
              </div>
              <a-table
                :rowSelection="{ selectedRowKeys: selectedRowKeysZyk, onChange: onSelectDataZyk }"
                :columns="importedColumnsZyk"
                :dataSource="importedDatasZyk"
                :scroll="{ y: 240 }"
                :pagination="paginationZyk"
                @change="onZykTableChange"
              >
                <span slot="action" slot-scope="text, record">
                  <a-tooltip placement="bottom" title="查看">
                    <span @click="clickActionRepository(record)" class="action-icon">
                      <i style="cursor: pointer" class="iconfont icon-chakan"></i>
                    </span>
                  </a-tooltip>
                </span>
              </a-table>
            </div>
            <div style="display: table-cell;width: 200px;border-left: 1px solid #ccc;">
              <div style="height: 35px; background: #1890ff; text-align: center; font-size: 18px; color: #fff; line-height: 35px;">
                关联知识点
                <a-tooltip placement="bottom">
                  <template slot="title">
                    <span>选择要导入题目的知识点</span>
                  </template>
                  <a-icon type="question-circle" style="color: #f00;cursor: pointer;" />
                </a-tooltip>
              </div>
              <div style="max-height: 500px;overflow: auto;">
                <tree-select :linkage="linkage" ref="treeImportedZyk" :list="treeList" v-if="importedZyk"></tree-select>
              </div>
            </div>
            <template slot="footer">
              <a-button @click="importedSureZyk" type="primary" html-type="submit">确定</a-button>
              <a-button @click.stop="importedCancelZyk">取消</a-button>
            </template>
          </a-modal>
          <!-- excel导入 -->
          <a-modal
            title="excel导入"
            class="oe-student"
            :visible="importExcel"
            width="40%"
            @cancel="importedCancelExcel"
          >
            <div class="oe-select">
              <span class="oe-manage-select">
                <h2>注意事项：</h2>
                <div>1、导入excel前建议先查看下载模板中的示例，按要求添加导入信息</div>
                <div>2、请按照模板规范顺序导入数据</div>
                <div>3、标红列为必填项</div>
              </span>
            </div>
            <div class="oe-select">
              <a href="/exam/excel/题目导入模板.xls">下载模板</a>
            </div>
            <div>
              <div class="clearfix">
                <a-upload :fileList="fileList" :remove="handleRemove" :beforeUpload="beforeUpload" accept=".xlsx, .xls">
                  <a-button> <a-icon type="upload" />选择文件 </a-button>
                </a-upload>
              </div>
            </div>
            <div class="oe-select-table">
              <a-table
                :columns="errorColumns"
                :dataSource="errorList"
                :pagination="false"
                v-if="errorList.length > 0"
              ></a-table>
            </div>
            <template slot="footer">
              <a-button
                type="primary"
                @click="handleUpload"
                :disabled="fileCount === 0"
                :loading="uploading"
                style="margin-top: 16px"
                >{{ uploading ? '上传中' : '上传' }}</a-button
              >
              <a-button @click.stop="importedCancelExcel">取消</a-button>
            </template>
          </a-modal>
          <!-- word导入 -->
          <a-modal title="word导入" class="oe-student" :visible="importword" width="40%" @cancel="importedCancelword">
            <div class="oe-select">
              <span class="oe-manage-select">
                <h2>注意事项：</h2>
                <div>1、导入word前建议先查看下载模板中的示例，按要求添加导入信息</div>
                <div>2、请按照模板规范顺序导入数据</div>
                <div>3、标红列为必填项</div>
              </span>
            </div>
            <div class="oe-select">
              <a href="/exam/excel/题库导入模板.docx">下载模板</a>
            </div>
            <div>
              <div class="clearfix">
                <a-upload
                  :fileList="fileListword"
                  :remove="handleRemoveword"
                  :beforeUpload="beforeUploadword"
                  accept=".docx"
                >
                  <a-button> <a-icon type="upload" />选择文件 </a-button>
                </a-upload>
              </div>
            </div>
            <div class="oe-select-table">
              <a-table
                :columns="errorColumns"
                :dataSource="errorListword"
                :pagination="false"
                v-if="errorListword.length > 0"
              ></a-table>
            </div>
            <template slot="footer">
              <a-button
                type="primary"
                @click="handleUploadword"
                :disabled="fileCountword === 0"
                :loading="uploading"
                style="margin-top: 16px"
                >{{ uploading ? '上传中' : '上传' }}</a-button
              >
              <a-button @click.stop="importedCancelword">取消</a-button>
            </template>
          </a-modal>
          <!-- word导入检查 -->
          <a-modal
            title="word导入检查"
            class="oe-student"
            :visible="importwordCheck"
            width="70%"
            @cancel="importwordCheck = false"
          >
            <div class="div-newImportQues">
              <div class="oe-select check_div">
                <div>
                  <span class="title-h">输入区</span>
                  <a-button type="primary" @click="checkWord" style="float: right; margin-right: 20px">{{
                    uploading ? '检查中' : '检查'
                  }}</a-button>
                </div>
                <div contenteditable="true" class="over-div">
                  <p v-for="(item, i) in listCheck" :key="i" ref="checkBox">
                    <span v-html="item"></span>
                    <br v-if="!item" />
                  </p>
                </div>
              </div>
              <div class="import_div">
                <div>
                  <span class="title-h">检查区</span>
                  <span v-if="errorNum > 0" class="error-span">识别错误：{{ errorNum }}题。请检查！</span>
                </div>
                <div class="over-div">
                  <div v-for="(item, i) in questions" :key="i">
                    <div>
                      <b>
                        <strong>{{ i + 1 }}、{{ item.QuestionType }}</strong>
                      </b>
                      <span v-html="item.Title"></span>
                    </div>
                    <div v-if="item.QuestionType == '单选题' || item.QuestionType == '多选题'">
                      <span v-for="(option, c) in item.Options" :key="c">
                        <p v-if="option">
                          <b>
                            <strong>{{ Alphabet[c] }}、</strong>
                          </b>
                          <span v-html="option"></span>
                        </p>
                      </span>
                    </div>
                    <div>
                      <p>
                        <span class="ques-weight">难度:</span>
                        {{ item.Difficulty }}
                      </p>
                      <p>
                        <span class="ques-weight">知识点:</span>
                        {{ item.Knowledge }}
                      </p>
                      <p>
                        <span class="ques-weight">答案:</span>
                        <span v-html="item.Answer"></span>
                      </p>
                      <p>
                        <span class="ques-weight">解析:</span>
                        <span v-html="item.Resolution"></span>
                      </p>
                      <p class="error_span" data-id="i" v-if="item.Error">
                        <span class="ques-weight">错误:</span>
                        <span v-html="item.Error"></span>
                      </p>
                    </div>
                    <div></div>
                    <div class="next-ques"></div>
                  </div>
                </div>
              </div>
            </div>
            <div>
              <div class="clearfix"></div>
            </div>
            <template slot="footer">
              <a-button
                type="primary"
                @click="upWord"
                :disabled="errorNum > 0"
                :loading="uploading"
                style="margin-top: 16px"
                >{{ uploading ? '导入中' : '导入' }}</a-button
              >
              <a-button @click.stop="importwordCheck = false">取消</a-button>
            </template>
          </a-modal>
        </a-tab-pane>
        <!-- <a-tab-pane tab="知识点" key="2" forceRender>
          <div class="oe-question-search">
            <span class="oe-question-text">名称：</span>
            <span class="oe-question-input">
              <a-input placeholder="请输入知识点名称" v-model="examName" />
            </span>
            <span class="oe-manage-btns">
              <a-button type="primary" @click.stop="getKonwledgeList">查询</a-button>
              <a-button
                v-if="operationList.includes('add/edit/del:ques')"
                type="primary"
                @click="clickkno('知识点新增')"
              >新增</a-button>
              <a-button v-if="operationList.includes('add/edit/del:ques')" @click="deleted">删除</a-button>
            </span>
          </div>
          <a-modal
            :title="titleText"
            class="oe-studentAdd"
            :visible="knowle"
            :confirmLoading="confirmLoading"
            @cancel="knowle = false"
          >
            <div class="oe-select">
              <a-form-model
                ref="ruleForm"
                :model="form"
                :rules="rules"
                :label-col="labelCol"
                :wrapper-col="wrapperCol"
              >
                <a-form-model-item label="知识点名称" prop="Title" ref="Title">
                  <a-input
                    v-model="form.Title"
                    @blur="
                      () => {
                        $refs.Title.onFieldBlur();
                      }
                    "
                  />
                </a-form-model-item>
                <a-form-model-item label="排序" prop="SortOrder" ref="SortOrder">
                  <a-input
                    v-model="form.SortOrder"
                    @blur="
                      () => {
                        $refs.SortOrder.onFieldBlur();
                      }
                    "
                  />
                </a-form-model-item>
              </a-form-model>
            </div>
            <template slot="footer">
              <a-button @click="addSure" type="primary" html-type="submit">确定</a-button>
              <a-button @click.stop="knowle = false">取消</a-button>
            </template>
          </a-modal>
          <div class="oe-question-container">
            <a-table
              :rowSelection="{ selectedRowKeys: knoleKeys, onChange: onSelectkno }"
              :columns="Knowledges"
              :dataSource="KnowledgeDatas"
              :pagination="paginationkno"
              @change="knoTableChange"
            >
              <span slot="SortOrder" slot-scope="text, record">
                <a-input-number
                  id="inputNumber"
                  v-model="record.SortOrder"
                  :min="1"
                  @change="onChange(val, record)"
                />
              </span>
              <span slot="action" slot-scope="text, record">
                <a-tooltip placement="bottom" title="编辑">
                  <span
                    v-if="operationList.includes('add/edit/del:ques')"
                    class="action-icon"
                    @click="clickkno('知识点编辑', record)"
                  >
                    <i class="iconfont icon-edit"></i>
                  </span>
                </a-tooltip>
                <a-tooltip placement="bottom" title="删除">
                  <span
                    v-if="operationList.includes('add/edit/del:ques')"
                    class="action-icon"
                    @click="clickkno('知识点删除', record)"
                  >
                    <i class="iconfont icon-delete"></i>
                  </span>
                </a-tooltip>
                <span v-if="!operationList.includes('add/edit/del:ques')">--</span>
              </span>
            </a-table>
          </div>
        </a-tab-pane> -->
        <a-tab-pane tab="知识点" key="2" forceRender>
          <tree v-if="defaultActiveKey == 2" :courseId="addid" :operationList="operationList"></tree>
        </a-tab-pane>
      </a-tabs>
    </div>
    <a-modal :title="questionText" :visible="questionBook" :closable="false" @cancel="handleOk" width="60%">
      <template slot="footer">
        <a-button key="submit" type="primary" :loading="loading" @click="handleOk">确定</a-button>
      </template>
      <questionView v-if="questionBook" :questionData="questionData" :subQuestionList="subQuestionList"></questionView>
    </a-modal>
    <a-modal :title="questionText" :visible="questionBook_zhzj" :closable="false" @cancel="handleOk" width="60%">
      <template slot="footer">
        <a-button key="submit" type="primary" :loading="loading" @click="handleOk">确定</a-button>
      </template>
      <questionViewZhzj
        v-if="questionBook_zhzj"
        :questionData="questionData"
        :answerList="answerList"
        :answerContentList="answerContentList"
        :subQuestionList="subQuestionList"
      ></questionViewZhzj>
    </a-modal>
  </div>
</template>

<script>
import topTip from '@/components/top-tip/index.vue';
import questionView from '@/components/question-bank/questionView/index.vue';
import questionViewZhzj from '@/components/question-bank/questionViewZhzj/index.vue';
import GetOperationList from '@/lib/mixin/methods.js';
import tree from '@/components/tree/index.vue';
import treeSelect from '@/components/treeSelect/index.vue';
export default {
  name: 'addExam',
  components: {
    topTip,
    questionView,
    questionViewZhzj,
    tree,
    treeSelect
  },
  mixins: [GetOperationList],
  data() {
    return {
      defaultActiveKey: '1',
      linkage: false,
      Alphabet: [
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'H',
        'I',
        'J',
        'K',
        'L',
        'M',
        'N',
        'O',
        'P',
        'Q',
        'R',
        'S',
        'T',
        'U',
        'V',
        'W',
        'X',
        'Y',
        'Z',
      ],
      userId: localStorage.getItem('userId'),
      projectId: '',
      knowledgeaOne: undefined,
      knowledgeaTwo: undefined,
      questionName: '',
      knowledgeaOneList: [],
      knowledgeaTwoList: [],
      labelCol: { span: 6 },
      wrapperCol: { span: 12 },
      isShow: false,
      imported: false,
      importedZyk: false,
      exportUrl: '',
      //题型
      typelist: [
        { id: 1, text: '单选题(客观)' },
        { id: 2, text: '多选题(客观)' },
        { id: 3, text: '判断(客观)' },
        { id: 4, text: '填空题(客观)' },
        { id: 5, text: '填空题(主观)' },
        { id: 6, text: '问答题(主观)' },
        { id: 7, text: '匹配题(客观)' },
        { id: 8, text: '阅读理解(客观)' },
        { id: 9, text: '完形填空(客观)' },
        { id: 11, text: '视听题(客观)' },
        { id: 12, text: '阅读理解(主观)' },
        { id: 13, text: '完形填空(主观)' },
      ],
      typelistZYK: [
        { id: 1, text: '单选题(客观)' },
        { id: 2, text: '多选题(客观)' },
        { id: 3, text: '填空题(主观)' },
        { id: 4, text: '判断(客观)' },
        { id: 5, text: '问答题(主观)' },
      ],
      //难度
      defficulty: [
        { id: 1, text: '非常简单' },
        { id: 2, text: '简单' },
        { id: 3, text: '一般' },
        { id: 4, text: '困难' },
        { id: 5, text: '非常困难' },
      ],
      //禁用状态
      disablestate: [
        { id: 0, text: '启用' },
        { id: 1, text: '禁用' },
      ],

      //资源库难度
      difficulty: [
        { id: 1, text: '简单' },
        { id: 2, text: '一般' },
        { id: 3, text: '困难' },
      ],

      projectList: [],
      zhzjKnowledgeId: '',
      treeList: [],
      // 分页配置
      paginationkno: {
        pageSizeOptions: ['10', '20', '50', '100', '1000'],
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.paginationkno.current = current;
          this.paginationkno.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          this.paginationkno.current = current;
          this.paginationkno.pageSize = pageSize;
        },
        buildOptionText(props) {
          return props.value + '条/页';
        },
        current: 1,
        pageSize: 10,
        total: 0,
      },
      pagination: {
        pageSizeOptions: ['10', '20', '50', '100', '1000'],
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.pagination.current = current;
          this.pagination.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          this.pagination.current = current;
          this.pagination.pageSize = pageSize;
        },
        buildOptionText(props) {
          return props.value + '条/页';
        },
        current: 1,
        pageSize: 10,
        total: 0,
      },
      loading: false,
      title: [{ text: '题库分类名称' }, { text: '题库', color: '#1890ff' }],
      //知识点
      knowle: false,
      visible: false,
      knowlege: [],
      form: {
        Title: '',
        SortOrder: '',
      },
      rules: {
        Title: [{ required: true, message: '请输入知识点', trigger: 'blur' }],
        SortOrder: [{ required: true, message: '请输入排序', trigger: 'blur' }],
      },
      titleText: '',
      examName: '',
      jishu: 1,
      KnowledgeDatas: [],
      Knowledges: [
        {
          title: '序号',
          dataIndex: 'number',
          align: 'center',
          key: 'number',
        },
        {
          title: '知识点名称',
          dataIndex: 'Title',
          sorter: true,
          key: 'Title',
          align: 'center',
        },
        {
          title: '排序',
          key: 'SortOrder',
          dataIndex: 'SortOrder',
          sorter: true,
          align: 'center',
          scopedSlots: { customRender: 'SortOrder' },
        },
        {
          title: '创建时间',
          dataIndex: 'DateCreated',
          key: 'DateCreated',
          sorter: true,
          align: 'center',
        },
        {
          title: '操作',
          key: 'action',
          sorter: true,
          align: 'center',
          scopedSlots: { customRender: 'action' },
          width: '20%'
        },
      ],
      //题库
      quiz: '',
      selectType1: [],
      selectType2: [],
      selectType3: [],
      selectedRowKeys: [],
      dataList: [],
      questionlistShow: true,
      columns: [
        {
          title: '序号',
          dataIndex: 'number',
          align: 'center',
          key: 'number',
        },
        {
          title: '题干',
          dataIndex: 'titleText',
          sorter: true,
          align: 'center',
          key: 'titleText',
          ellipsis: true,
          scopedSlots: { customRender: 'titleText' },
        },
        {
          title: '题型',
          dataIndex: 'questionType',
          sorter: true,
          align: 'center',
          key: 'questionType',
        },
        {
          title: '难度',
          dataIndex: 'difficultyLevel',
          sorter: true,
          align: 'center',
          key: 'difficultyLevel',
        },
        {
          title: '知识点',
          dataIndex: 'knowName',
          sorter: true,
          align: 'center',
          key: 'knowName',
          ellipsis: true,
        },
        {
          title: '题目来源',
          dataIndex: 'dataSource',
          sorter: true,
          align: 'center',
          key: 'dataSource',
        },
        {
          title: '创建者',
          dataIndex: 'creator',
          sorter: true,
          align: 'center',
          key: 'creator',
        },
        {
          title: '创建时间',
          dataIndex: 'dateCreated',
          sorter: true,
          align: 'center',
          key: 'dateCreated',
        },
        {
          title: '可用状态',
          dataIndex: 'isDisable',
          sorter: true,
          align: 'center',
          key: 'isDisable',
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
           width: '20%'
        },
      ],
      // 操作List
      operationList: [],
      // 、操作list
      IsOpList: [],
      KnowList: [],
      knowIds: [],
      CreateName: [],
      typeid: '',
      diffid: '',
      disablestateid: '',
      idquestion: [],
      konwids: [],
      idkno: [],
      lookItem: [],
      knoleKeys: [],
      paginationZjy: {
        pageSizeOptions: ['10', '20', '50', '100', '1000'],
        showQuickJumper: false,
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.paginationZjy.current = current;
          this.paginationZjy.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          // this.getExamList(current, pageSize);
          this.paginationZjy.current = current;
          this.paginationZjy.pageSize = pageSize;
        },
        current: 1,
        pageSize: 10,
        total: 0,
      },
      paginationZyk: {
        pageSizeOptions: ['10', '20', '50', '100', '1000'],
        showQuickJumper: false,
        showSizeChanger: true,
        showTotal(total) {
          return `共 ${total} 条`;
        },
        onShowSizeChange: (current, pageSize) => {
          this.paginationZyk.current = current;
          this.paginationZyk.pageSize = pageSize;
        },
        onChange: (current, pageSize) => {
          this.paginationZyk.current = current;
          this.paginationZyk.pageSize = pageSize;
        },
        buildOptionText(props) {
          return props.value + '条/页';
        },
        current: 1,
        pageSize: 10,
        total: 0,
      },
      importedColumns: [
        {
          title: '序号',
          dataIndex: 'Number',
          align: 'center',
        },
        {
          title: '题干',
          dataIndex: 'TitleText',
          sorter: true,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '题型',
          dataIndex: 'QuestionType',
          sorter: true,
          align: 'center',
        },
        {
          title: '所属课程',
          dataIndex: 'CourseName',
          sorter: true,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '难易程度',
          dataIndex: 'DefficultyLevel',
          sorter: true,
          align: 'center',
        },
        {
          title: '知识点',
          dataIndex: 'KnowledgeTitle',
          sorter: true,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
           width: '20%'
        },
      ],
      importedColumnsZyk: [
        {
          title: '序号',
          dataIndex: 'Number',
          align: 'center',
        },
        {
          title: '题干',
          dataIndex: 'contenttext',
          sorter: true,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '题型',
          dataIndex: 'basetype',
          sorter: true,
          align: 'center',
        },
        {
          title: '难易程度',
          dataIndex: 'difficulty',
          sorter: true,
          align: 'center',
        },
        {
          title: '知识点',
          dataIndex: 'nodename',
          sorter: true,
          align: 'center',
          ellipsis: true,
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
           width: '20%'
        },
      ],
      questionType: undefined,
      defficultyLevel: undefined,
      CourseName: '',
      knowledgeTitle: '',
      titleText_select: '',
      idsDataZjy: [],
      selectedRowKeysZjy: [],
      selectedRowKeysZyk: [],
      importedDatas: [],
      importedDatasZyk: [],
      importExcel: false,
      fileList: [],
      fileCount: 0,
      errorList: [],
      //word
      importedword: [],
      importword: false,
      fileListword: [],
      fileCountword: 0,
      errorListword: [],
      errorColumns: [
        {
          title: '序号',
          dataIndex: 'Number',
          align: 'center',
        },
        {
          title: '明细',
          dataIndex: 'Title',
          align: 'center',
        },
      ],
      questionBook: false,
      questionBook_zhzj: false,
      answerList: [],
      answerContentList: [],
      questionText: '',
      subQuestionList: [],
      courseTitle: '',
      checkDuplicateData: '0',
      importwordCheck: false,
      listCheck: [],
      questions: [],
      errorNum: 0,
      wordDataJson: [],
    };
  },
  props: {
    addid: {
      type: String,
      default: '',
    },
  },
  watch: {
    defaultActiveKey(e) {
      if (e == 1) {
        this.$refs.tree.ids = [];
        this.getOperation();
        this.getAllKnowledgeTreeList();
      }
    }
  },
  computed: {
    hasSelected() {
      return this.selectedRowKeys.length > 0;
    },
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      vm.getOperation();
    });
  },
  mounted() {
    this.getAllKnowledgeTreeList();
  },
  methods: {
    // 获取知识点
    getAllKnowledgeTreeList() {
      this.$http
        .post('/api/design/knowledgetree/getAllKnowledgeTreeList', {
          courseId: this.addid, //分类Id
        })
        .then((res) => {
          if (res.code > 0) {
            this.treeList = res.knowledgeList;
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    previewQuestion(quizid) {
      this.loading = true;
      this.$http
        .post('/api/design/questionbank/previewQuestion', {
          questionId: quizid,
        })
        .then((res) => {
          this.loading = false;
          if (res.code > 0) {
            this.questionBook = true;
            if (res.question.questionType == 1) {
              this.questionText = '单选题';
            } else if (res.question.questionType == 2) {
              this.questionText = '多选题';
            } else if (res.question.questionType == 3) {
              this.questionText = '判断题';
            } else if (res.question.questionType == 4) {
              this.questionText = '填空题(客观)';
            } else if (res.question.questionType == 5) {
              this.questionText = '填空题(主观)';
            } else if (res.question.questionType == 6) {
              this.questionText = '问答题';
            } else if (res.question.questionType == 7) {
              this.questionText = '匹配题';
            } else if (res.question.questionType == 8) {
              this.questionText = '阅读理解(客观)';
            } else if (res.question.questionType == 9) {
              this.questionText = '完形填空(客观)';
            } else if (res.question.questionType == 11) {
              this.questionText = '视听题(客观)';
            }
            this.questionData = res.question;
            this.subQuestionList = res.subQuestionList;
          }
        });
    },
    diffchange(val) {
      this.diffid = val;
    },
    typechange(val) {
      this.typeid = val;
    },
    disableStateChange(val) {
      this.disablestateid = val;
    },

    projectchange(val) {
      this.projectId = val;
      this.getKnowledgeZhzj(1);
      if (this.knowledgeaOne) {
        this.knowledgeaOne = '';
        this.knowledgeaTwo = '';
      }
    },
    knowledgeaOnechange(val) {
      this.knowledgeaOne = val;
      this.getKnowledgeZhzj(2);
      if (this.knowledgeaTwo) {
        this.knowledgeaTwo = undefined;
      }
    },
    knowledgeaTwochange(val) {
      this.knowledgeaTwo = val;
      this.getZykDataList();
    },
    //我的课程
    getCourseList() {
      let that = this;
      this.$http
        .post('/api/design/course/getCourseList', {
          isDelete: 0,
        })
        .then((res) => {
          if (res.code == 1) {
            let ruleTitle = res.list.filter((item) => item.Id === this.addid);
            that.title[1].text = ruleTitle[0].CourseName;
          }
        });
    },
    //判断知识点类型
    clickkno(type, data) {
      let index = this.IsOpList.findIndex((el) => {
        return el.Name == type;
      });
      if (index > -1) {
        if (this.IsOpList[index].IsRead && !this.IsOpList[index].IsWrite) {
          this.$message.info('您没有该操作权限，请先进行添加！');
          return;
        }
      }
      switch (type) {
        case '知识点新增':
          this.knowle = true;
          this.titleText = '新建知识点';
          // this.form = '';
          this.form = data ? data : {};
          break;
        case '知识点编辑':
          this.knowle = true;
          this.lookItem = data;
          this.titleText = '编辑知识点';
          this.$http
            .post('/api/design/knowledge/getKnowledgeInfo', {
              id: data.Id,
            })
            .then((res) => {
              this.form = res.knowledgeInfo;
            });
          break;
        case '知识点删除':
          this.$confirm({
            title: '提示',
            content: '你确定要删除该知识点吗？',
            centered: true,
            onOk: () => {
              // var Id = [data.Id];
              this.$http
                .post('/api/design/knowledge/deleteKnowledge', {
                  ids: data.Id,
                  courseId: this.addid,
                })
                .then((rst) => {
                  if (rst.code === 1) {
                    this.$message.success(rst.msg);
                    this.getKonwledgeList();
                    // this.selectedRowKeys = [];
                  } else {
                    this.$message.error(rst.msg);
                  }
                });
            },
            onCancel() {},
          });
          break;
      }
    },
    //判断操作类型
    clickAction(type, data) {
      let index = this.IsOpList.findIndex((el) => {
        return el.Name == type;
      });
      if (index > -1) {
        if (this.IsOpList[index].IsRead && !this.IsOpList[index].IsWrite) {
          this.$message.info('您没有该操作权限，请先进行添加！');
          return;
        }
      }
      switch (type) {
        case '查看':
          this.previewQuestion(data.questionId);
          // this.$router.push({
          //   name: 'detailQuestion',
          //   params: {
          //     quizid: data.questionId,
          //     datalist: data,
          //     courseid: this.addid
          //   }
          // });
          break;
        case '题库编辑':
          this.$router.push({
            name: 'editQuestion',
            params: {
              quizid: data.questionId,
              datalist: data,
              courseid: this.addid,
            },
          });
          break;
        case '题库删除':
          this.$confirm({
            title: '提示',
            content: '你确定要删除该题目吗？',
            centered: true,
            onOk: () => {
              this.loading = true;
              this.$http
                .post('/api/design/questionbank/deleteQuestion', {
                  ids: data.questionId,
                })
                .then((rst) => {
                  this.loading = false;
                  if (rst.code === 1) {
                    this.$message.success(rst.msg);
                    this.konwids = [];
                    this.selectedRowKeys = [];
                    this.getQuestionBankList();
                  } else {
                    this.$message.error(rst.msg);
                  }
                });
            },
          });
          break;
        case '新增题目':
          this.$router.push({
            name: 'newQuestion',
            params: {
              courseid: this.addid,
            },
          });
          break;
      }
    },
    // 查看职教云的题目
    clickActionIcve(data) {
      this.loading = true;
      this.$http
        .post('/api/design/question/previewQuestion_zjy', {
          questionId: data.Id,
        })
        .then((res) => {
          this.loading = false;
          if (res.code > 0) {
            this.questionBook = true;
            if (res.question.questionType == 1) {
              this.questionText = '单选题';
            } else if (res.question.questionType == 2) {
              this.questionText = '多选题';
            } else if (res.question.questionType == 3) {
              this.questionText = '判断题';
            } else if (res.question.questionType == 4) {
              this.questionText = '填空题(客观)';
            } else if (res.question.questionType == 5) {
              this.questionText = '填空题(主观)';
            } else if (res.question.questionType == 6) {
              this.questionText = '问答题';
            } else if (res.question.questionType == 7) {
              this.questionText = '匹配题';
            } else if (res.question.questionType == 8) {
              this.questionText = '阅读理解(客观)';
            } else if (res.question.questionType == 9) {
              this.questionText = '完形填空(客观)';
            } else if (res.question.questionType == 11) {
              this.questionText = '视听题(客观)';
            }
            this.questionData = res.question;
            this.subQuestionList = res.subQuestionList;
          }
        });
    },
    // 查看资源库的题目
    clickActionRepository(data) {
      this.loading = true;
      this.$http
        .post('/api/design/question/previewQuestion_zhzj', {
          questionId: data.id,
        })
        .then((res) => {
          this.loading = false;
          if (res.code > 0) {
            this.questionBook_zhzj = true;
            if (res.question.questionType == 1) {
              this.questionText = '单选题';
            } else if (res.question.questionType == 2) {
              this.questionText = '多选题';
            } else if (res.question.questionType == 3) {
              this.questionText = '判断题';
            } else if (res.question.questionType == 4) {
              this.questionText = '填空题(客观)';
            } else if (res.question.questionType == 5) {
              this.questionText = '填空题(主观)';
            } else if (res.question.questionType == 6) {
              this.questionText = '问答题';
            } else if (res.question.questionType == 7) {
              this.questionText = '匹配题';
            } else if (res.question.questionType == 8) {
              this.questionText = '阅读理解(客观)';
            } else if (res.question.questionType == 9) {
              this.questionText = '完形填空(客观)';
            } else if (res.question.questionType == 11) {
              this.questionText = '视听题(客观)';
            }
            this.questionData = res.question;
            this.answerList = res.answerList;
            this.answerContentList = res.answerContentList;
            this.subQuestionList = res.subQuestionList;
          }
        });
    },
    //保存知识点
    addSure() {
      let id = this.titleText === '编辑知识点' ? this.lookItem.Id : '';
      this.loading = true;
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.$http
            .post('/api/design/knowledge/saveKnowledge', {
              id,
              sortOrder: this.form.SortOrder,
              title: this.form.Title,
              courseId: this.addid,
            })
            .then((res) => {
              this.loading = false;
              this.lookItem = '';
              if (res.code === 1) {
                this.knowle = false;
                this.$message.success(res.msg);
                this.form.Title = '';
                this.getKonwledgeList();
                this.getKnowledgeList();
              } else {
                this.$message.error(res.msg);
              }
            });
        } else {
          this.loading = false;
          return false;
        }
      });
    },
    //修改知识点
    modify() {
      if (!this.getIsWrite('修改知识点')) {
        return;
      }
      if (this.selectedRowKeys.length > 0) {
        this.getAllKnowledgeTreeList();
        this.$refs.tree.ids = [];
        this.visible = true;
      } else {
        this.$warning({
          title: '提示消息',
          content: '请选择要修改知识点的题目',
        });
      }
    },
    sureModify() {
      this.$http
        .post('/api/design/questionbank/editKnow', {
          ids: this.idquestion,
          knowledgeIds: this.$refs.treemodal.ids,
        })
        .then((res) => {
          if (res.code == 1) {
            this.visible = false;
            this.konwids = [];
            this.selectedRowKeys = [];
            this.knowlege = [];
            this.getQuestionBankList();
            this.$message.success(res.msg);
            this.getOperation();
            this.getAllKnowledgeTreeList();
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    // //搜索多选
    selectTeacher(val) {
      this.knowIds = val;
    },
    selectknowle(val) {
      this.konwids = val;
    },
    // 获取页面操作
    getOperation() {
      this.loading = true;
      this.GetOperationList('courseId', this.addid).then((rst) => {
        this.loading = false;
        this.operationList = [];
        this.IsOpList = [];
        if (rst.code === 1) {
          if (rst.list.length) {
            rst.list.forEach((item) => {
              if (item.IsWrite) {
                this.operationList.push(item.Name);
              }
              this.IsOpList = rst.list;
            });
            // this.operationList = rst.list;
          }
          this.getQuestionBankList();
          this.getKnowledgeList();
          this.getKonwledgeList();
          this.getCourseList();
          this.exportUrl =
            '/api/design/questionbank/getQuestionList?export=1&courseId=' +
            this.addid +
            '&knowledgeId=' +
            this.knowIds +
            '&quesTitle=' +
            this.quiz +
            '&questionType=' +
            this.typeid +
            '&difficultyLevel=' +
            this.diffid;
          this.courseTitle = rst.courseTitle;
        } else {
          this.$message.error(rst.msg);
        }
      });
    },
    // 判断是否是只读
    getIsWrite(type) {
      type = 'add/edit/del:ques';
      let index = this.IsOpList.findIndex((el) => {
        return el.Name === type;
      });
      if (index > -1) {
        if (this.IsOpList[index].IsRead && !this.IsOpList[index].IsWrite) {
          this.$message.info('您没有该操作权限！');
          return false;
        } else {
          return true;
        }
      }
    },
    //删除题目
    deleteQuestion() {
      if (!this.getIsWrite('题库删除')) {
        return;
      }
      if (this.selectedRowKeys.length > 0) {
        this.$confirm({
          title: '提示',
          content: '你确定要删除该信息吗？',
          centered: true,
          onOk: () => {
            this.$http
              .post('/api/design/questionbank/deleteQuestion', {
                ids: this.idquestion,
              })
              .then((rst) => {
                if (rst.code === 1) {
                  this.$message.success(rst.msg);
                  this.getQuestionBankList();
                  this.selectedRowKeys = [];
                } else {
                  this.$message.error(rst.msg);
                }
              });
          },
          onCancel() {},
        });
      } else {
        this.$warning({
          title: '提示消息',
          content: '请选择要删除的题目',
        });
      }
    },
    //批量删除知识点
    deleted() {
      if (!this.getIsWrite('知识点删除')) {
        return;
      }
      if (this.knoleKeys.length > 0) {
        this.$confirm({
          title: '提示',
          content: '你确定要删除该信息吗？',
          centered: true,
          onOk: () => {
            this.$http
              .post('/api/design/knowledge/deleteKnowledge', {
                ids: this.idkno,
                courseId: this.addid,
              })
              .then((rst) => {
                if (rst.code === 1) {
                  this.$message.success(rst.msg);
                  this.getKonwledgeList();
                  this.knoleKeys = [];
                } else {
                  this.$message.error(rst.msg);
                }
              });
          },
          onCancel() {},
        });
      } else {
        this.$warning({
          title: '提示消息',
          content: '请选择要删除的知识点',
        });
      }
    },
    //获取知识点
    getKnowledgeList() {
      this.$http
        .post('/api/design/question/getKnowList', {
          courseId: this.addid,
        })
        .then((rst) => {
          this.KnowList = rst;
        });
    },
    //获取知识点列表
    getKonwledgeList(current, pageSize, sort) {
      this.loading = true;
      this.$http
        .post('/api/design/knowledge/getKonwledgeList', {
          courseId: this.addid,
          title: this.examName,
          sort: sort || '',
          pageSize: pageSize || 10,
          page: current || 1,
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code == 1) {
            this.KnowledgeDatas = [];
            this.paginationkno.current = rst.pagination.pageIndex;
            this.paginationkno.pageSize = rst.pagination.pageSize;
            this.paginationkno.total = rst.pagination.totalCount;
            if (rst.list && rst.list.length) {
              rst.list.forEach((item, index) => {
                let number = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index + 1;
                this.KnowledgeDatas.push({
                  number,
                  ...item,
                });
              });
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    //批量禁用
    disableQuestionClick() {
      if (this.selectedRowKeys.length > 0) {
        this.$confirm({
          title: '提示',
          content: '你确定要禁用该题目吗？',
          centered: true,
          onOk: () => {
            this.$http
              .post('/api/design/questionbank/disableQuestion', {
                ids: this.idquestion,
              })
              .then((rst) => {
                if (rst.code === 1) {
                  this.$message.success(rst.msg);
                  this.getQuestionBankList();
                  this.selectedRowKeys = [];
                } else {
                  this.$message.error(rst.msg);
                }
              });
          },
          onCancel() {},
        });
      } else {
        this.$warning({
          title: '提示消息',
          content: '请选择要禁用的题目',
        });
      }
    },

    //批量解禁
    relieveDisableQuestionClick() {
      if (this.selectedRowKeys.length > 0) {
        this.$confirm({
          title: '提示',
          content: '你确定要解禁该题目吗？',
          centered: true,
          onOk: () => {
            this.$http
              .post('/api/design/questionbank/relieveDisableQuestion', {
                ids: this.idquestion,
              })
              .then((rst) => {
                if (rst.code === 1) {
                  this.$message.success(rst.msg);
                  this.getQuestionBankList();
                  this.selectedRowKeys = [];
                } else {
                  this.$message.error(rst.msg);
                }
              });
          },
          onCancel() {},
        });
      } else {
        this.$warning({
          title: '提示消息',
          content: '请选择要解禁的题目',
        });
      }
    },

    //题目查重/取消查重
    checkDuplicateClick() {
      var sort = '';
      if (this.checkDuplicateData == '0') {
        this.checkDuplicateData = '1';
        sort = 'titleText';
        this.questionlistShow = false;
        this.columns[1] = {
          title: '题干',
          dataIndex: 'titleText',
          sorter: true,
          align: 'center',
          key: 'titleText',
          ellipsis: true,
          defaultSortOrder: 'ascend',
          scopedSlots: { customRender: 'titleText' },
        };
        setTimeout(() => {
          this.questionlistShow = true;
        }, 200);
      } else {
        this.checkDuplicateData = '0';
        this.questionlistShow = false;
        this.columns[1] = {
          title: '题干',
          dataIndex: 'titleText',
          sorter: true,
          align: 'center',
          key: 'titleText',
          ellipsis: true,
          scopedSlots: { customRender: 'titleText' },
        };
        setTimeout(() => {
          this.questionlistShow = true;
        }, 200);
      }
      this.getQuestionBankList(1, 10, sort);
    },
    //获取题目列表
    getQuestionBankList(current, pageSize, sort) {
      this.loading = true;
      this.$http
        .post('/api/design/questionbank/getQuestionList', {
          knowledgeId: this.$refs.tree.ids,
          courseId: this.addid,
          quesTitle: this.quiz,
          questionType: this.typeid,
          difficultyLevel: this.diffid,
          // title: this.search,
          page: current || 1,
          pageSize: pageSize || 10,
          sort: sort || '',
          checkDuplicateData: this.checkDuplicateData,
          disableState: this.disablestateid,
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code == 1) {
            this.dataList = [];
            this.pagination.current = rst.pagination.pageIndex;
            this.pagination.pageSize = rst.pagination.pageSize;
            this.pagination.total = rst.pagination.totalCount;
            this.isShow = rst.isZjySchool;
            if (rst.list && rst.list.length) {
              rst.list.forEach((item, index) => {
                let number = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index + 1;
                this.dataList.push({
                  number,
                  ...item,
                });
              });
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    // 点击table排序
    onTableChange(pagenation, filter, sort) {
      let sortOrder = '';
      if (sort.order) {
        if (sort.order == 'ascend') {
          sortOrder = sort.columnKey;
        } else if (sort.order == 'descend') {
          sortOrder = '-' + sort.columnKey;
        } else {
          sortOrder = '';
        }
      }
      this.getQuestionBankList(pagenation.current, pagenation.pageSize, sortOrder);
    },
    knoTableChange(pagenation, filter, sort) {
      let sortOrder = '';
      if (sort.order) {
        if (sort.order == 'ascend') {
          sortOrder = sort.columnKey;
        } else if (sort.order == 'descend') {
          sortOrder = '-' + sort.columnKey;
        } else {
          sortOrder = '';
        }
      }
      this.getKonwledgeList(pagenation.current, pagenation.pageSize, sortOrder);
    },
    onChange(value, record) {
      this.$http
        .post('/api/design/knowledge/setKnowledgeSort', {
          id: record.Id,
          sortOrder: record.SortOrder,
        })
        .then((res) => {
          if (res.code == 1) {
            this.$message.success(res.msg);
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    //题库
    onSelectquestion(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      var ids = [];
      for (let i = 0; i < selectedRows.length; i++) {
        ids.push(selectedRows[i].questionId);
      }
      this.idquestion = ids;
    },
    //知识点
    onSelectkno(selectedRowKeys, selectedRows) {
      this.knoleKeys = selectedRowKeys;
      var ids = [];
      for (let i = 0; i < selectedRows.length; i++) {
        ids.push(selectedRows[i].Id);
      }
      this.idkno = ids;
    },
    importQues() {
      if (!this.getIsWrite('职教云导入')) {
        return;
      }
      this.getZjyDataList();
    },
    importZykQues() {
      if (!this.getIsWrite('资源库导入')) {
        return;
      }

      this.questionName = undefined;
      this.questionType = undefined;
      this.defficultyLevel = undefined;
      this.projectId = undefined;

      this.getProjectZhzj();
    },
    // 点击table排序
    onZjyTableChange(paginationZjy, filter, sort) {
      let sortOrder = '';
      if (sort.order) {
        if (sort.order == 'ascend') {
          sortOrder = sort.columnKey;
        } else if (sort.order == 'descend') {
          sortOrder = '-' + sort.columnKey;
        } else {
          sortOrder = '';
        }
      }
      this.getZjyDataList(paginationZjy.current, paginationZjy.pageSize, sortOrder);
    },
    // 点击table排序
    onZykTableChange(paginationZyk, filter, sort) {
      let sortOrder = '';
      if (sort.order) {
        if (sort.order == 'ascend') {
          sortOrder = sort.columnKey;
        } else if (sort.order == 'descend') {
          sortOrder = '-' + sort.columnKey;
        } else {
          sortOrder = '';
        }
      }
      this.getZykDataList(paginationZyk.current, paginationZyk.pageSize, sortOrder);
    },
    //获取职教云题目
    getZjyDataList(page, pageSize, sortOrder) {
      this.loading = true;
      this.$http
        .post('/api/design/QuestionBank/getZjyQuestionList', {
          questionType: this.questionType,
          CourseName: this.CourseName,
          defficultyLevel: this.defficultyLevel,
          titleText: this.titleText_select,
          knowledgeTitle: this.knowledgeTitle,
          sort: sortOrder || '',
          page: page || 1,
          pageSize: pageSize || 10,
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code == 1) {
            this.imported = true;
            this.importedDatas = [];
            this.paginationZjy.current = rst.pagination.pageIndex;
            this.paginationZjy.pageSize = rst.pagination.pageSize;
            this.paginationZjy.total = rst.pagination.totalCount;
            if (rst.questionList.length) {
              rst.questionList.forEach((item, index) => {
                let number = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index + 1;
                this.importedDatas.push({
                  ...item,
                  Number: number,
                });
              });
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },

    getProjectZhzj() {
      this.$http
        .post('/api/design/question/getKnowledgeSearchList', {
          userId: this.userId,
        })
        .then((res) => {
          if (!res || res.length == 0) {
            this.$message.error('暂无题目！');
            return false;
          }
          this.projectList = res;
          this.projectId = res[0]['Id'];
          this.getKnowledgeZhzj(1);
        });
    },

    getKnowledgeZhzj(fristLoad) {
      if (!this.knowledgeaOne && fristLoad == 2) {
        this.getZykDataList();
        return;
      }
      this.$http
        .post('/api/design/question/getKnowledgeSearchList', {
          userId: this.userId,
          projectId: this.projectId,
          knowledgeId: this.knowledgeaOne,
        })
        .then((r) => {
          if (fristLoad == 1) {
            if (r && r.length > 0) {
              this.knowledgeaOneList = r;
            }
            //this.knowledgeaOne = r[0]['Id'];
            this.getKnowledgeZhzj(2);
          } else {
            this.knowledgeaTwoList = r;
            this.getZykDataList();
          }
        });
    },

    eventknowledge(userId) {
      var h = this;
      $('.selector_knowledge').change(function () {
        procjectId = $('.selector').val();
        this.zhzjKnowledgeId = $(this).val();
        this.getZykDataList(userId, procjectId, h.zhzjKnowledgeId, 'limbLinkage2', 2);
      });
    },

    //获取资源库题目
    getZykDataList(page, pageSize, sortOrder) {
      this.loading = true;
      var nodePath = this.projectId;
      var knowledgeId = this.knowledgeaOne;
      var knowledgeb = this.knowledgeaTwo;

      if (knowledgeId) {
        nodePath = nodePath + '/' + knowledgeId;
      }
      if (knowledgeb) {
        nodePath = nodePath + '/' + knowledgeb;
      }

      this.$http
        .post('/api/design/question/getQuestionList', {
          userId: this.userId,
          questionName: this.questionName,
          questionType: this.questionType,
          difficulty: this.defficultyLevel,
          projectId: this.projectId,
          nodepath: nodePath,
          sort: this.paginationZyk.sort || '',
          page: page || 1,
          pageSize: pageSize,
        })
        .then((rst) => {
          this.loading = false;
          if (rst.code == 1) {
            this.importedZyk = true;
            this.importedDatasZyk = [];
            this.selectedRowKeysZyk = [];
            this.idsDataZjy = [];
            this.paginationZyk.current = rst.pagination.pageIndex;
            this.paginationZyk.pageSize = rst.pagination.pageSize;
            this.paginationZyk.total = rst.pagination.totalCount;
            if (rst.result.length) {
              rst.result.forEach((item, index) => {
                let number = (rst.pagination.pageIndex - 1) * rst.pagination.pageSize + index + 1;
                this.importedDatasZyk.push({
                  ...item,
                  key: item.id,
                  Number: number,
                });
              });
            }
          } else {
            this.$message.error(rst.msg);
          }
        });
    },
    //选择要导入的数据
    onSelectDataZjy(selectedRowKeys, selectedRows) {
      this.selectedRowKeysZjy = selectedRowKeys;
      var ids = [];
      for (let i = 0; i < selectedRows.length; i++) {
        ids.push(selectedRows[i].Id);
      }
      this.idsDataZjy = ids;
    },
    importedSure() {
      this.saveImpot(1);
    },
    //选择要导入的数据
    onSelectDataZyk(selectedRowKeys, selectedRows) {
      this.selectedRowKeysZyk = selectedRowKeys;
      var ids = [];
      for (let i = 0; i < selectedRows.length; i++) {
        ids.push(selectedRows[i].id);
      }
      this.idsDataZjy = ids;
    },
    importedSureZyk() {
      this.saveImpot(2);
    },
    //保存导入的数据
    saveImpot(type) {
      if (this.idsDataZjy.length === 0) {
        this.$message.error('请选择要导入的数据');
        return;
      };
      let knowledgeIds = '';
      if (type == 1) {
        knowledgeIds = this.$refs.treeQuestionzjy.ids.join(',');
      } else {
        knowledgeIds = this.$refs.treeImportedZyk.ids.join(',');
      }
      this.$confirm({
        title: '提示',
        content: '确认导入选择的数据吗？',
        centered: true,
        onOk: () => {
          this.loading = true;
          this.$http
            .post('/api/design/Question/uploadQuestionFromZJYorZHZJ', {
              courseOpenId: this.addid,
              questionIds: this.idsDataZjy, //要删除的成员id数组
              uploadType: type,
              knowledgeIds: knowledgeIds
            })
            .then((res) => {
              this.loading = false;
              if (res.code > 0) {
                if (type == 1) {
                  this.imported = false;
                } else {
                  this.importedZyk = false;
                }
                this.typeid = undefined;
                this.getQuestionBankList();
                this.selectedRowKeysZjy = [];
                this.selectedRowKeysZyk = [];
                this.$message.success(res.msg);
              } else {
                this.$message.error(res.msg);
              }
            });
        },
        onCancel() {},
      });
    },
    importedCancel() {
      this.imported = false;
    },
    importedCancelZyk() {
      this.importedZyk = false;
    },
    importedCancelExcel() {
      this.importExcel = false;
    },
    //点击excel导入
    importExcelQues() {
      if (!this.getIsWrite('Excel导入')) {
        return;
      }
      this.fileCount = 0;
      this.errorList = [];
      this.fileList = [];
      this.importExcel = true;
    },
    importedCancelword() {
      this.importword = false;
    },
    //点击word导入
    importworddQues() {
      if (!this.getIsWrite('Word导入')) {
        return;
      }
      this.fileCountword = 0;
      this.errorListword = [];
      this.fileListword = [];
      this.importword = true;
    },
    //删除文件
    handleRemove(file) {
      const index = this.fileList.indexOf(file);
      const newFileList = this.fileList.slice();
      newFileList.splice(index, 1);
      this.fileList = newFileList;
      this.errorList = [];
    },
    handleRemoveword(file) {
      const index = this.fileListword.indexOf(file);
      const newFileList = this.fileListword.slice();
      newFileList.splice(index, 1);
      this.fileListword = newFileList;
      this.errorListword = [];
    },
    //选择文件
    beforeUpload(file) {
      this.fileList = [];
      this.fileCount = 1;
      this.fileList = [...this.fileList, file];
      return false;
    },
    beforeUploadword(file) {
      this.fileListword = [];
      this.fileCountword = 1;
      this.fileListword = [...this.fileListword, file];
      return false;
    },
    //上传
    handleUpload() {
      const { fileList } = this;
      this.loading = true;
      const formData = new FormData();
      fileList.forEach((file) => {
        formData.append('files[]', file);
        formData.append('courseId', this.addid);
      });
      this.uploading = true;
      this.$http.post('/api/design/questionBank/importExcel', formData).then((res) => {
        this.fileCount = 0;
        this.errorList = [];
        this.uploading = false;
        this.loading = false;
        if (res.code > 0) {
          this.importExcel = false;
          this.getQuestionBankList();
          this.getKonwledgeList();
          this.$message.success(res.msg);
        } else {
          this.$message.error(res.msg);
          if (res.list && res.list.length) {
            res.list.forEach((item, index) => {
              this.errorList.push({
                Title: item,
                Number: index + 1,
              });
            });
          }
        }
      });
    },
    handleUploadword() {
      this.loading = true;
      const { fileListword } = this;
      const formData = new FormData();
      fileListword.forEach((file) => {
        formData.append('files[]', file);
        formData.append('courseId', this.addid);
      });
      this.uploading = true;
      this.$http.post('/api/design/QuestionWord/importWordNew', formData).then((res) => {
        this.fileCountword = 0;
        this.errorListword = [];
        this.uploading = false;
        this.loading = false;
        if (res.code == 1) {
          this.importwordCheck = true;
          this.listCheck = JSON.parse(res.list);
          this.questions = JSON.parse(res.dataJSON);
          this.wordDataJson = res.dataJSON;
          this.errorNum = res.errorNum;
        } else if (res.code == -1) {
          this.$message.error(res.msg);
        } else {
          this.$message.error('请求失败，请刷新也页面重试！');
        }
      });
    },
    checkWord() {
      var checkBoxList = this.$refs.checkBox;
      //console.log(list);
      var list = [];
      for (let i = 0; i < checkBoxList.length; i++) {
        list.push(checkBoxList[i].innerHTML.replace(/<\/?span[^>]*>/gi, '').replace(/<!---->/g, ''));
      }
      this.uploading = true;
      this.loading = true;
      this.$http.post('/api/design/QuestionWord/importWordNewStr', { body: JSON.stringify(list) }).then((res) => {
        this.fileCountword = 0;
        this.errorListword = [];
        this.uploading = false;
        this.loading = false;
        if (res.code == 1) {
          this.listCheck = [];
          this.questions = [];
          this.errorNum = 0;
          this.listCheck = JSON.parse(res.list);
          this.questions = JSON.parse(res.dataJSON);
          this.wordDataJson = res.dataJSON;
          this.errorNum = res.errorNum;
        } else if (res.code == -1) {
          this.$message.error(res.msg);
        } else {
          this.$message.error('请求失败，请刷新也页面重试！');
        }
      });
    },
    upWord() {
      this.uploading = true;
      this.loading = true;
      this.$http
        .post('/api/design/QuestionWord/importWordNewJSON', { data: this.wordDataJson, courseId: this.addid })
        .then((res) => {
          this.fileCountword = 0;
          this.errorListword = [];
          this.uploading = false;
          this.loading = false;
          if (res.code == 1) {
            this.listCheck = [];
            this.questions = [];
            this.errorNum = 0;
            this.wordDataJson = [];
            this.importwordCheck = false;
            this.importword = false;
            this.getQuestionBankList();
            this.getKonwledgeList();
            this.$message.success(res.msg);
          } else {
            this.$message.error('请求失败，请刷新也页面重试！');
          }
        });
    },
    handleUploadword_old() {
      this.loading = true;
      const { fileListword } = this;
      const formData = new FormData();
      fileListword.forEach((file) => {
        formData.append('files[]', file);
        formData.append('courseId', this.addid);
      });
      this.uploading = true;
      this.$http.post('/api/design/question/importWord', formData).then((res) => {
        this.fileCountword = 0;
        this.errorListword = [];
        this.uploading = false;
        this.loading = false;
        if (res.code > 0) {
          this.importword = false;
          this.getQuestionBankList();
          this.getKonwledgeList();
          this.$message.success(res.msg);
        } else {
          this.$message.error(res.msg);
          // this.errorList = res.list;
          if (res.list.length) {
            res.list.forEach((item, index) => {
              this.errorListword.push({
                Title: item.LineNo + item.ErrorInfo,
                Number: index + 1,
              });
              // console.log(this.errorListword);
            });
          }
        }
      });
    },
    handleOk() {
      this.questionBook = false;
      this.questionBook_zhzj = false;
    },
  },
};
</script>

<style></style>
